﻿using Business;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookManageSys.User
{
    public partial class SpecialBook : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    RecommendationEngineBusiness recommendationEngine = new RecommendationEngineBusiness();
                    string username = Session["UserName"].ToString();
                    List<ProductsEntity> recommendedProducts = recommendationEngine.GetProductRecommendations(username);

                    // 将推荐的产品数据绑定到GridView控件
                    gvRecommendedProducts.DataSource = recommendedProducts;
                    gvRecommendedProducts.DataBind();
                }catch
                {
                    ProductsBusiness productsBusiness = new ProductsBusiness();
                    DataTable dt = productsBusiness.GetSpecialData();
                    gvRecommendedProducts.DataSource = dt;
                    gvRecommendedProducts.DataBind();
                }
            }
        }

        protected void gvRecommendedProducts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "详情")
            {
                Response.Redirect("BookDetail.aspx?productid=" + e.CommandArgument);
            }
        }
    }
}